package com.yl.entity;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.yl.constant.Const;
import com.yl.constant.Warn;
import com.yl.entity.cdc.SettingsDataQuota;
import com.yl.entity.cdc.SettingsThreshold;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PrimaryWarn implements Serializable {

    private static final long serialVersionUID = 1L;

    // 原数据对象
    private MultiDataEntity multiDataEntity;

    // 告警指标信息
    private SettingsDataQuota quota;
    // 告警阈值信息
    private SettingsThreshold th;
    // 告警等级
    private Warn warn;
    // 告警时间
    private Date warnTime;
    // 告警数值
    private Double dataValue;
    // 告警信息
    private String message;

    // 处理时间
    private Date time;

    /**
     * 邮件和短信推送信息
     */
    public String msg() {
        return StrUtil.format(Const.TPL_WARN_MSG, this.multiDataEntity.getProject().getName(),
                this.warn.getName(), this.multiDataEntity.getTarget().getCode(), this.quota.getName(),
                this.multiDataEntity.getTargetType().getName(), DateUtil.date(this.warnTime).toString(),
                this.dataValue, this.th.getLower(), this.th.getUpper());
    }

}
